package com.ztsjglxt.controller.base;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;

import com.alibaba.fastjson.JSON;
import com.ztsjglxt.core.Ibasecommon;
import com.ztsjglxt.entity.utils.JsonWrite;


/**
 * 公共Controller 
 * 
 * @author
 * @since 所有Controller的父类
 */
@Controller
public class BaseController {

	// @Resource
	// public Ibasecommon bllbase;
	// @Resource
	// public IbasedictSearch blldict;
	
	public boolean issuccess = true;

	public JsonWrite jsonWrite = new JsonWrite();

	// @Resource
	// IsyslogoperManager blllogoper;

	// @Resource
	// IsyslogloginManager bllloglogi;

	/**
	 * 输出HTML脚本
	 */
	public void writeJson(HttpServletResponse response, Object obj) {
		this.writeJson(response, obj, "utf-8");
	}

	/**
	 * 输出HTML脚本带格式
	 */
	protected void writeJson(HttpServletResponse response, Object obj,
			String charset) {
		String json = JSON.toJSONString(obj);
		response.setContentType("text/html;charset=" + charset);
		response.setDateHeader("Expires", -10);
		PrintWriter out = null;
		try {
			out = response.getWriter();
			out.println(json);
			out.flush();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (out != null) {
				out.close();
			}
		}
	}


	/**
	 * 生成按钮
	 */
	public String outputbtn( String menuid, Ibasecommon bllbase) {
		String zero="0";
		String minusOne="-1";
		if (StringUtils.isBlank(menuid) == true || menuid.equals(zero)
				|| menuid.equals(minusOne)) {
			return "";
		}
		StringBuffer html = new StringBuffer();
		List<Map> lst = bllbase.getlistfromtable("menu",
					" kind =0 and Is_delete=1 and pid=" + menuid, "menu_Order asc");
		for (int i = 0; i < lst.size(); i++) {
			html.append("<button id='" + lst.get(i).get("id").toString()
					+ "' name='" + lst.get(i).get("menu_Name").toString()
					+ "' class='layui-btn layui-btn-small layui-btn-red'  onclick='" + lst.get(i).get("href").toString()
					+ "'> <i class='" + lst.get(i).get("menu_icon").toString()
					+ "'></i>&nbsp;" + lst.get(i).get("menu_Name").toString()
					+ "</button> &nbsp;");
		}
		return html.toString();
	}

	


}